﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefMaintenanceRecord" :model="stateMaintenanceRecord.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_PlanId_FormItem" prop="Entity.PlanId" :label="$t('message.autotrans._Model_MaintenanceRecord_Plan')">
            <el-select v-model="stateMaintenanceRecord.vmModel.Entity.PlanId" disabled clearable>
               <el-option v-for="item in stateMaintenanceRecord.AllPlans" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_EquipmentId_FormItem" prop="Entity.EquipmentId" :label="$t('message.autotrans._Model_MaintenanceRecord_Equipment')">
            <el-select v-model="stateMaintenanceRecord.vmModel.Entity.EquipmentId" disabled clearable>
               <el-option v-for="item in stateMaintenanceRecord.AllEquipments" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaintainerId_FormItem" prop="Entity.MaintainerId" :label="$t('message.autotrans._Model_MaintenanceRecord_Maintainer')">
            <el-select v-model="stateMaintenanceRecord.vmModel.Entity.MaintainerId" disabled clearable>
               <el-option v-for="item in stateMaintenanceRecord.AllMaintainers" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_MaintenanceTime_FormItem" prop="Entity.MaintenanceTime" :label="$t('message.autotrans._Model_MaintenanceRecord_MaintenanceTime')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.MaintenanceTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_FinishTime_FormItem" prop="Entity.FinishTime" :label="$t('message.autotrans._Model_MaintenanceRecord_FinishTime')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.FinishTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ActualHours_FormItem" prop="Entity.ActualHours" :label="$t('message.autotrans._Model_MaintenanceRecord_ActualHours')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.ActualHours" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Result_FormItem" prop="Entity.Result" :label="$t('message.autotrans._Model_MaintenanceRecord_Result')">
            <el-select v-model="stateMaintenanceRecord.vmModel.Entity.Result" disabled clearable>
               <el-option key="Completed" value="Completed" :label="$t('message.autotrans._Enum_MaintenanceResultEnum_Completed')"></el-option>
               <el-option key="Cancelled" value="Cancelled" :label="$t('message.autotrans._Enum_MaintenanceResultEnum_Cancelled')"></el-option>
               <el-option key="Delayed" value="Delayed" :label="$t('message.autotrans._Enum_MaintenanceResultEnum_Delayed')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Note_FormItem" prop="Entity.Note" :label="$t('message.autotrans._Model_MaintenanceRecord_Note')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.Note" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Files_FormItem" prop="Entity.Files" :label="$t('message.autotrans._Model_MaintenanceRecord_Files')">
            <wtm-upload-image v-model="stateMaintenanceRecord.vmModel.Entity.Files" clearable :multi="true"  disabled thumb-width="128"/>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateTime_FormItem" prop="Entity.CreateTime" :label="$t('message.autotrans._Model_MaintenanceRecord_CreateTime')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.CreateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateTime_FormItem" prop="Entity.UpdateTime" :label="$t('message.autotrans._Model_MaintenanceRecord_UpdateTime')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.UpdateTime" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_CreateBy_FormItem" prop="Entity.CreateBy" :label="$t('message.autotrans._Model_MaintenanceRecord_CreateBy')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.CreateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpdateBy_FormItem" prop="Entity.UpdateBy" :label="$t('message.autotrans._Model_MaintenanceRecord_UpdateBy')">
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.UpdateBy" disabled clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_IsValid_FormItem" prop="Entity.IsValid" :label="$t('message.autotrans._Model_MaintenanceRecord_IsValid')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MaintenanceRecord_IsValid')}), trigger: 'blur' }]" >
            <el-input v-model="stateMaintenanceRecord.vmModel.Entity.IsValid" disabled clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onCloseMaintenanceRecord"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageEquipmentManagementMaintenanceRecordDetails;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { maintenancerecordApi } from '/@/api/equipmentmanagement/maintenancerecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMaintenanceRecord = ref();
const stateMaintenanceRecord = reactive({
    vmModel: {
	  Entity:{
        PlanId: null,
        EquipmentId: null,
        MaintainerId: null,
        MaintenanceTime: undefined,
        FinishTime: undefined,
        ActualHours: null,
        Result: undefined,
        Note: '',
        Files: null,
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
        IsValid: undefined,
        ID:null,
      },

	},
    
    AllPlans: [] as any[],
    AllEquipments: [] as any[],
    AllMaintainers: [] as any[],
});

// 取消
const onCloseMaintenanceRecord = () => {
    closeDialog();
};

// 提交
const onSubmitMaintenanceRecord = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefMaintenanceRecord.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            maintenancerecordApi().edit(stateMaintenanceRecord.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/EquipmentManagement/MaintenanceRecord/GetMaintenancePlans',[],false).then(x=>{stateMaintenanceRecord.AllPlans = x});
    other.getSelectList('/api/EquipmentManagement/MaintenanceRecord/GetEquipments',[],false).then(x=>{stateMaintenanceRecord.AllEquipments = x});
    other.getSelectList('/api/EquipmentManagement/MaintenanceRecord/GetFrameworkUsers',[],false).then(x=>{stateMaintenanceRecord.AllMaintainers = x});
    if (ci.attrs["wtmdata"]) {
		stateMaintenanceRecord.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMaintenanceRecord.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	maintenancerecordApi().get(stateMaintenanceRecord.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateMaintenanceRecord.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

